<template>
    <bi-form class="shop-number-level-price" ref="form">
        <bi-icon :loading="loading" v-if="loading" />
        <template v-if="!loading">
            <div  class="no-info" v-if="length==0">
                <template v-if="noText==''">
                当前未设置会员等级 <bi-button type="link" @click="$go({app:'shop',controller:'admin.MemberLevel',action:'index'})">前往设置</bi-button>
                </template>
                <template v-if="noText!=''">
                    {{noText}}
                </template>
            </div>

            <bi-form-item v-for="(item,index) in consumeList" :label="item.title" >
                <div class="row g-2">
                    <div class="col-md-6">
                        <bi-input v-model="item.price" :min="0" type="number" placeholder="会员价格" />
                    </div>
                    <div class="col-md-6">
                        <bi-input v-model="item.stock" :min="0" type="int" placeholder="会员库存" />
                    </div>
                </div>
            </bi-form-item>

            <bi-form-item v-for="(item,index) in specialList" :label="item.title" >
                <div class="row g-2">
                    <div class="col-md-6">
                        <bi-input v-model="item.price" :min="0" type="number" placeholder="会员价格" />
                    </div>
                    <div class="col-md-6">
                        <bi-input v-model="item.stock" :min="0" type="int" placeholder="会员库存" />
                    </div>
                </div>
            </bi-form-item>
             
        </template>
    </bi-form>
</template>


<script>
export default{
    data(){
        return {
            length:0,
            consumeList:[],
            specialList:[],
            loading:false,   
        }
    },
    props:{
        data:{
            type:Object,
            default:function(){
                return {};
            }
        },
        noText:{
            type:String,
            default:''
        }
    },
    methods:{
        refresh(){
            this.loading = true;
            this.$ajax({
                url:this.$url({app:'shop',controller:'admin.MemberLevel',action:'list'}),
                success:(res)=>{

                    this.loading = false;
                    this.length = res.length;

                    for(let i=0;i<res.length;i++){
                        if (res[i].type =='consume'){
                            this.consumeList.push(res[i]);
                        }

                        if (res[i].type =='special'){
                            this.specialList.push(res[i]);
                        }
                    }


                }
            });
        },
        getData(){
            return [];
        },
        check(){
            return true;
        }
    },
    mounted(){
        this.refresh();
    }

}
</script>

<style>
.shop-number-level-price{
    padding: 5px;
}
</style>